package com.example.demo.core;

import com.sun.org.apache.regexp.internal.RE;
import lombok.Builder;
import lombok.Data;

/**
 * 统一API响应结果封装
 */
@Builder
@Data
public class Result<T> {
    private int code;
    private String message;
    private T data;

    public static Result fail() {
        return Result.fail(null);
    }

    public static Result fail(String msg) {
        return Result.fail(msg, null);
    }

    public static Result fail(Object data) {
        return Result.fail(null, data);
    }

    public static Result fail(String msg, Object data) {
        return Result.result(ResultCode.FAIL.code, msg, data);
    }

    public static Result success() {
        return Result.success(null);
    }

    public static Result success(String msg) {
        return Result.success(msg, null);
    }

    public static Result success(Object data) {
        return Result.success(null, data);
    }

    public static Result success(String msg, Object data) {
        return Result.result(ResultCode.SUCCESS.code, msg, data);
    }

    public static Result result(int code, String msg) {
        return Result.result(code, msg, null);
    }

    public static Result result(int code, Object data) {
        return Result.result(code, null, data);
    }

    public static Result result(int code, String msg, Object data) {
        return Result.builder().code(code).message(msg).data(data).build();
    }
}
